//
//  OrderDetailHeadCell.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/19.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "OrderDetailHeadCell.h"
#import "ProgressView.h"
#import "OrderDetailData.h"
#import "UIImageView+WebCache.h"
#import "config.h"
#import "NSString+StringHight.h"


@interface OrderDetailHeadCell ()

@property (nonatomic,strong)ProgressView *proView;

@property (weak, nonatomic) IBOutlet UIView *progressContentView;


@property (weak, nonatomic) IBOutlet UIImageView *buyerImgView;

@property (weak, nonatomic) IBOutlet UILabel *buyerName;

//@property (weak, nonatomic) IBOutlet UIButton *buyerMobile;
@property (weak, nonatomic) IBOutlet UITextView *buyerMobile;


@property (weak, nonatomic) IBOutlet UILabel *orderCodeLab;

@property (weak, nonatomic) IBOutlet UILabel *timeLab;

@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@property (weak, nonatomic) IBOutlet UILabel *mianTitleLab;

@property (weak, nonatomic) IBOutlet UILabel *subTitleLab;

@property (weak, nonatomic) IBOutlet UILabel *dorLab;

@property (weak, nonatomic) IBOutlet UILabel *rmbLab;
@property (weak, nonatomic) IBOutlet UILabel *buyerAddress;


@end

@implementation OrderDetailHeadCell





+(instancetype) cellWithTableView:(UITableView *)tableview{

    static NSString *ID = @"OrderDetailHeadCell";
    OrderDetailHeadCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderDetailHeadCell" owner:nil options:nil]lastObject];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        
        cell.proView = [ProgressView creatView];
        
        int mid = cell.progressContentView.frame.size.height-cell.proView.frame.size.height;
        
        
        [cell.proView setFrame:CGRectMake(0,mid/2, cell.progressContentView.frame.size.width, cell.progressContentView.frame.size.height-mid)];
        [cell.progressContentView addSubview:cell.proView];
        
        
        
//        cell.proView = [ProgressView creatView];
//        [cell.proView setFrame:CGRectMake(0, 10, cell.progressContentView.frame.size.width, cell.progressContentView.frame.size.height - 20)];
////        [cell.proView setFrame:CGRectMake(0, 0, cell.progressContentView.frame.size.width, cell.progressContentView.frame.size.height)];
//        [cell.progressContentView addSubview:cell.proView];
        
        [[cell  buyerMobile]setTintColor:UIColorFromRGB(0x333333)];
         cell.buyerMobile.editable = NO;
    }
    
    return cell;
}


+(CGFloat)getHight:(CellBaseData*)data withTableView:(UITableView*)tableView{

    return 364;
}

-(void)setData:(OrderDetailData*)data{
    
    [self.proView setPogressState:data.state];
    
    [self.buyerImgView sd_setImageWithURL:[NSURL URLWithString:data.buyerImg] placeholderImage:[UIImage imageNamed:DEFAULT_IMG]];
    
    [self.buyerName setText:data.buyerName];
    
    
    NSMutableAttributedString *attString = [data.buyerMobile attributedStringFromStingWithFont:self.buyerMobile.font withLineSpacing:0];
    NSRange contentRange = {0, [attString length]};
     [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
    [self.buyerMobile setAttributedText:attString];
//    [self.buyerMobile setTitle:data.buyerMobile forState:UIControlStateNormal];
    
    
    [self.orderCodeLab setText:data.orderCode];
    [self.timeLab setText:data.time];
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:data.imgPath] placeholderImage:[UIImage imageNamed:DEFAULT_IMG]];
    [self.mianTitleLab setText:data.title];
    [self.subTitleLab setText:data.subleTitle];
    [self.dorLab setText:data.dol];
    
    [self.rmbLab setText:[NSString stringWithFormat:@"约¥%@万",data.rmb]];
//    [self.rmbLab setText:data.rmb];
    
    self.buyerAddress.text = data.buyerAddress;
}

#pragma mark 拨打电话
- (IBAction)btnOnClick:(UIButton *)sender {
    
    if (sender.currentTitle.length == 0) {
        return;
    }
   
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",sender.currentTitle];
   
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];}


@end
